<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery/jquery.min.js"></script>

</head>
<body>

<button id="btn1">查询所有</button>
<button id="btn2">查询单个</button>
<button id="btn3">新增</button>
<button id="btn4">修改</button>
<button id="btn5">删除</button>
</body>
<script>
    $(function () {
        //查询所有
        $('#btn1').click(function () {
            $.get("/departments",function (data) {
                console.log(data);
            })
        });
        //查询单个
        $('#btn2').click(function (id) {
            $.get("/departments/1",function (data) {
                console.log(data);
            })
        });
        //添加
        $('#btn3').click(function () {
            $.post("/departments",{name:"部门1",sn:"ngbm1"},function (data) {
                console.log(data);
            })
        });
        //修改
        $('#btn4').click(function () {
            $.ajax({
                url:"/departments",
                type:"PUT",
                data:{id:88,name:"部门1",sn:"ngbm1"},
                success:function (data) {
                    console.log(data);
                }
            })
        });
        //删除
        $('#btn5').click(function () {
            $.ajax({
                url:"/departments/88",
                type:"DELETE",

                success:function (data) {
                    console.log(data);
                }
            })
        });

    })
</script>
</html>